<?php
 session_start();
 
 
 
 include_once("connexion.php"); 	


 
 

if(isset($_GET['id'])){

$erreur ="";
	$resultat = mysqli_query($bdd,"SELECT * FROM biens WHERE id=".$_GET['id']);
	$top = mysqli_fetch_array($resultat);

$sql_photo="SELECT * FROM photos WHERE id_bien=".$_GET['id'];
$req_photo=mysqli_query($bdd, $sql_photo);
$Photo = mysqli_fetch_array($req_photo);
					
				
 
$sql_ville = "SELECT * FROM villes";
$req_ville=mysqli_query($bdd, $sql_ville);
$Ville = mysqli_fetch_array($req_ville);

$sql_pays = "SELECT * FROM pays";
$req_pays = mysqli_query($bdd,$sql_pays);
$Pays = mysqli_fetch_array($req_pays);

$sql_type = "SELECT * FROM type_bien";
$req_type = mysqli_query($bdd,$sql_type);
$Type = mysqli_fetch_array($req_type);


if (isset($_POST['louer'])) {
	
	$id_bien = $_GET['id'];
	$id_locatair = $_SESSION['id_user'];

	$louer_query = "INSERT INTO historiques VALUES ('',
		'".$id_bien."',
		'".$top['debut_dispo']."',
		'".$top['fin_dispo']."',
		'".$top['tarif_semaine']."',
		'".$id_locatair."')";
	$louer = mysqli_query($bdd,$louer_query);

	if ($louer == true) {

		header('location:detail_profil.php');
		$erreur = "Bien correctement reserver";
	}else{
		$erreur = "Probleme de location le bien et peut etre deja louer sur la periode proposer";
	}

	}
}
 



include_once("info_bien.html");


?>